<script setup lang="ts">
import useCategoryStore from '@/store/modules/category'
import { onMounted } from 'vue'
defineProps(['scene'])
//获取一级分类的后端数据
const getC1 = async () => {
  await useCategory.getC1()
}
let useCategory = useCategoryStore()
//一级分类的值变化
const handler = () => {
  //清除后面两级之前的id
  useCategory.c2Id = ''
  useCategory.c3Arr = []
  useCategory.c3Id = ''
  useCategory.getC2()
}
//二级分类值的变化
const handler1 = () => {
  useCategory.c3Id = ''
  useCategory.getC3()
}
onMounted(() => {
  getC1()
})
</script>

<template>
  <div>
    <el-card>
      <el-form :inline="true">
        <el-form-item label="一级分类">
          <el-select
            v-model="useCategory.c1Id"
            @change="handler"
            :disabled="scene == 1 ? true : false"
          >
            <el-option
              v-for="item in useCategory.c1Arr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="二级分类">
          <el-select
            v-model="useCategory.c2Id"
            @change="handler1"
            :disabled="scene == 1 ? true : false"
          >
            <el-option
              v-for="item in useCategory.c2Arr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="三级分类">
          <el-select
            v-model="useCategory.c3Id"
            :disabled="scene == 1 ? true : false"
          >
            <el-option
              v-for="item in useCategory.c3Arr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<style scoped></style>
